<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:bi="http://java.sun.com/jsf/composite/bill">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>
                    <h:panelGroup rendered="#{!channelStaffPaymentBillController.printPreview}" styleClass="alignTop" >
                        <p:panel header="Staff Payments" >
                            <h:panelGrid columns="1" >
                                <h:panelGrid columns="2" >
                                    <h:panelGrid columns="2">
                                        <p:outputLabel value="Speciality" />
                                        <p:autoComplete style="min-width: 400px!important;" forceSelection="true" value="#{channelStaffPaymentBillController.speciality}" id="acSpeciality"
                                                        completeMethod="#{doctorSpecialityController.completeSpeciality}" var="mysp" itemLabel="#{mysp.name}" itemValue="#{mysp}"
                                                        converter="specilityCon"   >
                                            <f:ajax event="itemSelect" execute="acSpeciality" render="scStaff" />
                                        </p:autoComplete>

                                        <p:outputLabel value="Staff" />
                                        <p:autoComplete minQueryLength="2"  style="width: 400px;"
                                                        forceSelection="true" 
                                                        value="#{channelStaffPaymentBillController.currentStaff}" id="scStaff"
                                                        completeMethod="#{channelStaffPaymentBillController.completeStaff}" var="mys" 
                                                        itemLabel="#{mys.person.nameWithTitle}" itemValue="#{mys}"
                                                        converter="stfcon"   >                                            
                                            <p:ajax event="itemSelect" update="lstSelect" process="scStaff"  
                                                    listener="#{channelStaffPaymentBillController.fillSessions}"></p:ajax>
                                        </p:autoComplete>
                                        <p:outputLabel value="Consider Date" />
                                        <p:selectBooleanCheckbox value="#{channelStaffPaymentBillController.considerDate}" >
                                            <p:ajax update="fDate tDate" process="@this" event="change" />
                                        </p:selectBooleanCheckbox>
                                        <p:outputLabel value="From Date" />
                                        <p:calendar value="#{channelStaffPaymentBillController.fromDate}" id="fDate" styleClass="dateTimePicker"
                                                    disabled="#{!channelStaffPaymentBillController.considerDate}" navigator="false" pattern="dd MMMM yyyy HH:mm:ss" />
                                        <p:outputLabel value="To Date" />
                                        <p:calendar value="#{channelStaffPaymentBillController.toDate}" id="tDate" styleClass="dateTimePicker"
                                                    disabled="#{!channelStaffPaymentBillController.considerDate}" navigator="false" pattern="dd MMMM yyyy HH:mm:ss" />
                                        <p:outputLabel value="Session" />
                                        <p:selectOneMenu  id="lstSelect" converter="sscon"  
                                                          value="#{channelStaffPaymentBillController.selectedServiceSession}" style="min-width: 100%;" >
                                            <f:selectItem itemLabel="Select"  ></f:selectItem>
                                            <f:selectItems  value="#{channelStaffPaymentBillController.serviceSessionList}" var="ses" 
                                                            itemValue="#{ses}" 
                                                            itemLabel="#{ses.name} - #{ses.dayString}" ></f:selectItems>
                                        </p:selectOneMenu>
                                        <p:commandButton ajax="false" value="Process" action="#{channelStaffPaymentBillController.calculateDueFees}"/>
                                        <p:commandButton ajax="false" value="Clear" action="#{channelStaffPaymentBillController.makenull()}"/>
                                        <p:watermark value="Speciality" for="acSpeciality"/>
                                        <p:watermark value="Staff" for="scStaff"/>
                                    </h:panelGrid>



                                </h:panelGrid>


                                <p:dataTable id="tblFee" value="#{channelStaffPaymentBillController.dueBillFees}" selection="#{channelStaffPaymentBillController.payingBillFees}" rowIndexVar="i" var="bf" rowKey="#{bf.id}" >

                                    <f:ajax  event="rowSelectCheckbox" execute="tblFee" listener="#{channelStaffPaymentBillController.performCalculations()}"   
                                             render=":#{p:component('scStaff')}  :#{p:component('lblDue')} :#{p:component('lblPay')} tblFee"  />  

                                    <f:ajax  event="rowUnselectCheckbox" execute="tblFee" listener="#{channelStaffPaymentBillController.performCalculations()}"   
                                             render=":#{p:component('scStaff')}  :#{p:component('lblDue')} :#{p:component('lblPay')} tblFee"  />  

                                    <f:ajax  event="toggleSelect" execute="tblFee" listener="#{channelStaffPaymentBillController.performCalculations()}"   
                                             render=":#{p:component('scStaff')}  :#{p:component('lblDue')} :#{p:component('lblPay')} tblFee"  />

                                    <f:ajax  event="rowSelect" execute="tblFee" listener="#{channelStaffPaymentBillController.performCalculations()}"   
                                             render=":#{p:component('scStaff')}  :#{p:component('lblDue')} :#{p:component('lblPay')} tblFee"  />

                                    <p:column selectionMode="multiple" ></p:column>

                                    <p:column headerText="No">
                                        <h:outputLabel value="#{i+1}">
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Bill Id">
                                        <h:outputLabel value="#{bf.bill.insId}">
                                        </h:outputLabel>
                                    </p:column>
                                    
                                    <p:column headerText="Appoinment No">
                                        <h:outputLabel value="#{bf.bill.singleBillSession.serialNo}">
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Patient">
                                        <h:outputLabel value="#{bf.bill.patient.person.nameWithTitle}" rendered="#{bf.bill.patientEncounter eq null}"/>                                    
                                        <h:outputLabel value="#{bf.bill.patientEncounter.patient.person.nameWithTitle}"/>                                    
                                    </p:column>

                                    <p:column headerText="Booked on" rendered="false">
                                        <h:outputLabel value="#{bf.bill.createdAt}">
                                            <f:convertDateTime pattern="dd MMMM yyyy" />
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Channel on" rendered="false">
                                        <h:outputLabel value="#{bf.bill.singleBillSession.sessionDate}">
                                            <f:convertDateTime pattern="dd MMMM yyyy" />
                                        </h:outputLabel>
                                    </p:column>
                                    
                                    
                                    
                                    <p:column headerText="Refundable" rendered="#{webUserController.hasPrivilege('Developers')}">
                                        <h:outputLabel value="#{bf.bill.singleBillSession.serviceSession.originatingSession.refundable}">
                                        </h:outputLabel>
                                    </p:column>
                                    
                                    
                                    <p:column headerText="Absent" rendered="#{webUserController.hasPrivilege('Developers')}">
                                        <h:outputLabel value="#{bf.bill.singleBillSession.absent}">
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column headerText="Cancel" rendered="#{webUserController.hasPrivilege('Developers')}">
                                        <h:outputLabel value="#{bf.bill.cancelled}">
                                        </h:outputLabel>
                                    </p:column>
                                    
                                    <p:column headerText="Refund" rendered="#{webUserController.hasPrivilege('Developers')}">
                                        <h:outputLabel value="#{bf.bill.refunded}">
                                        </h:outputLabel>
                                    </p:column>
                                    
                                    <p:column headerText="Appoinment Date">
                                        <h:outputLabel value="#{bf.bill.appointmentAt}">
                                            <f:convertDateTime pattern="dd MMMM yyyy" />
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Charge" >
                                        <h:outputLabel  value="#{bf.feeValue}" />
                                    </p:column>

                                </p:dataTable>



                                <p:panel id="pTotals"  >
                                    <f:facet name="header" >
                                        <h:outputLabel value="Payment Details" />
                                    </f:facet>
                                    <h:panelGrid columns="2" >
                                        <h:outputLabel value="Total Due" ></h:outputLabel>
                                        <h:outputLabel id="lblDue" value="#{channelStaffPaymentBillController.totalDue}" >
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                        <h:outputLabel value="Paying This time" ></h:outputLabel>
                                        <h:outputLabel id="lblPay"  value="#{channelStaffPaymentBillController.totalPaying }" >
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>  
                                    </h:panelGrid>
                                </p:panel>
                                <h:panelGroup >

                                    <h:outputLabel value="Payment Method" ></h:outputLabel>
                                    <p:selectOneMenu  id="cmbPay" style="width: 400px;" value="#{channelStaffPaymentBillController.paymentMethod}" >
                                        <!--<f:selectItem itemLabel="Please select a Payment method" />-->
                                        <f:selectItems value="#{enumController.paymentMethodsWithoutCredit}"/>
                                    </p:selectOneMenu>

                                    <p:commandButton ajax="false" value="Pay" action="#{channelStaffPaymentBillController.settleBill()}" onclick="onSubmitButton();" >
                                        <!--<f:ajax execute="@this cmbPay tblFee scStaff" render="@all" />-->
                                    </p:commandButton>
                                </h:panelGroup>
                            </h:panelGrid>

                        </p:panel>
                    </h:panelGroup>

<!--                    <h:panelGroup id="gpBillPreview" rendered="#{channelStaffPaymentBillController.printPreview}">
                        <p:commandButton value="Print" styleClass="noPrintButton" ajax="false" action="#" >
                            <p:printer target="gpBillPreview" ></p:printer>
                        </p:commandButton>
                        <p:commandButton ajax="false" styleClass="noPrintButton" value="New Bill" action="#{channelStaffPaymentBillController.makenull()}" />

                        <bi:staffBill  controller="#{channelStaffPaymentBillController}" bill="#{channelStaffPaymentBillController.current}" dup="false"/>
                    </h:panelGroup>-->

                    <h:panelGroup id="gpBillPreview" rendered="#{channelStaffPaymentBillController.printPreview}">
                        <p:commandButton value="Print" styleClass="noPrintButton" ajax="false" action="#" >
                            <p:printer target="gpBillPreview" ></p:printer>
                        </p:commandButton>
                        <p:commandButton ajax="false" styleClass="noPrintButton" value="New Bill" action="#{channelStaffPaymentBillController.makenull()}" />

                        <h:panelGroup rendered="#{sessionController.loggedPreference.opdBillPaperType eq 'FiveFivePaper'}">
                            <h:panelGroup rendered="#{!sessionController.loggedPreference.pharmacyBillPrabodha}">
                                <bi:staffBill_1  controller="#{channelStaffPaymentBillController}" bill="#{channelStaffPaymentBillController.current}" dup="false"/>
                            </h:panelGroup>
                        </h:panelGroup>


                        <h:panelGroup rendered="#{sessionController.loggedPreference.opdBillPaperType eq 'PosPaper'}">
                            <h:panelGroup rendered="#{sessionController.loggedPreference.pharmacyBillPrabodha}" > 
                                <bi:paymentReciptPosDouble controller="#{channelStaffPaymentBillController}" bill="#{channelStaffPaymentBillController.current}" dup="false"/>
                            </h:panelGroup>
                        </h:panelGroup>
                    </h:panelGroup>
                </h:form>



            </ui:define>


        </ui:composition>


    </h:body>
</html>
